// case.js
const state = {
  caseMsg: {}, // 初始为空对象
  caseList: [] // 新增的 caseList 数组，初始为空数组
};

const mutations = {
  SET_CASE_MSG(state, msg) {
    state.caseMsg = msg;
  },
  SET_CASE_LIST(state, list) {
    state.caseList = list;
  },
  ADD_TO_CASE_LIST(state, item) {
    state.caseList.push(item);
  },
  REMOVE_FROM_CASE_LIST(state, index) {
    state.caseList.splice(index, 1);
  }
};

const actions = {
  updateCaseMsg({ commit }, msg) {
    commit('SET_CASE_MSG', msg);
  },
  setCaseList({ commit }, list) {
    commit('SET_CASE_LIST', list);
  },
  addToCaseList({ commit }, item) {
    commit('ADD_TO_CASE_LIST', item);
  },
  removeFromCaseList({ commit }, index) {
    commit('REMOVE_FROM_CASE_LIST', index);
  }
};

const getters = {
  getCaseMsg: state => state.caseMsg,
  getCaseList: state => state.caseList
};

export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters
};

/*
获取 caseMsg 的值：this.$store.getters['casep/getCaseMsg']
更新 caseMsg 的值：this.$store.dispatch('casep/updateCaseMsg', newMsgObject)

获取 caseList：this.$store.getters['casep/getCaseList']
设置整个 caseList：this.$store.dispatch('casep/setCaseList', newArray)
向 caseList 添加新项：this.$store.dispatch('casep/addToCaseList', newItem)
从 caseList 移除项：this.$store.dispatch('casep/removeFromCaseList', indexToRemove)
 */
